package com.nowcoder.community.service;

import com.mysql.cj.log.Log;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Scope;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

/**
 * @author shkstart
 * @create 2022-02-11 10:55
 */
@Service
@Scope("prototype")
@Slf4j
public class AlphaService {

    public AlphaService(){
        System.out.println("实例化AlphaService");
    }

    /**
     * 执行构造函数后执行
     **/
    @PostConstruct
    public void init(){
        System.out.println("初始化AlphaService");
    }

    /**
     * 对象销毁前执行
     **/
    @PreDestroy
    public void destory() {
        System.out.println("销毁AlphaService");
    }


    // 让该方法在多线程环境下,被异步的调用.
    @Async
    public void execute1() {
        log.debug("execute1");
    }

    /*@Scheduled(initialDelay = 10000, fixedRate = 1000)*/
    public void execute2() {
        log.debug("execute2");
    }
}
